﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLTV.Public;

namespace QLTV.DAL
{
    public class TacGiaDAL
    {

        ConnectionData connect;
        public DataTable LoadDuLieu()
        {
            try
            {
                connect = new ConnectionData();
                return connect.GetData("TacGia_Load");
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable LoadMaTacGia(TacGiaDTO tgDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@matg";
                value[0] = tgDTO.MaTG;
                return connect.GetData("TacGia_LoadDuLieuCotMaTG", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int nhapTacGia(TacGiaDTO tgDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 2;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@matg";
                value[0] = tgDTO.MaTG;
                name[1] = "@tentg";
                value[1] = tgDTO.TenTG;

                return connect.UpdateData("TacGia_InsertUpdate", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public int TacGia_Xoa(TacGiaDTO tgDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] values = new object[Nparamater];
                name[0] = "@MaTG";
                values[0] = tgDTO.MaTG;
                return connect.UpdateData("TacGia_Xoa", name, values, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
        public DataTable TimTheoTen(TacGiaDTO tgDTO)
        {
            try
            {
                connect = new ConnectionData();
                int Nparamater = 1;
                string[] name = new string[Nparamater];
                object[] value = new object[Nparamater];
                name[0] = "@search";
                value[0] = tgDTO.TenTG;
                return connect.GetData("TacGia_TimTheoTen", name, value, Nparamater);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    }
}
